#include "TaskUtils.h"

void TaskUtils::iniFileWrite(const QString &filePath, const QString &group, const QString &key, const QVariant &value)
{
    QSettings iniFile(filePath, QSettings::IniFormat);
    iniFile.setIniCodec("UTF-8");
    iniFile.beginGroup(group);
    iniFile.setValue(key, value);
    iniFile.endGroup();
}

QVariant TaskUtils::iniFileRead(const QString &filePath, const QString &group, const QString &key, const QVariant &defaultValue)
{
    QSettings iniFile(filePath, QSettings::IniFormat);
    iniFile.setIniCodec("UTF-8");
    iniFile.beginGroup(group);
    QVariant value = iniFile.value(key, defaultValue);
    iniFile.endGroup();
    return value;
}

void TaskUtils::createSettingsFile(const QString &filePath)
{
    if (QFile::exists(filePath))
        return;

    QSettings iniFile(filePath, QSettings::IniFormat);
    iniFile.setIniCodec("UTF-8");
    iniFile.beginGroup("Connection");
    iniFile.setValue("DatabaseType", "QSQLITE");
    iniFile.setValue("HostName", "");
    iniFile.setValue("Port", "");
    iniFile.setValue("Database", "../sql/dbremind.db");
    iniFile.setValue("UserName", "");
    iniFile.setValue("Password", "");
    iniFile.endGroup();
}
